<template>
<!-- 团队建设列表 -->
  <div class="wise-salary-list">
    <div class="team-search">
      <van-dropdown-menu>
        <van-dropdown-item v-model="workType" :options="typeList" @change="handleDrop" />
      </van-dropdown-menu>
      <div class="search">
        <van-search left-icon="search" v-model="title" :clearable="false" placeholder="请输入标题搜索" @search="handleSearch" />
      </div>
    </div>
    <van-list
      v-model="loading"
      loading-text="加载中"
      :finished="finished"
      finished-text="没有更多了"
      @load="onload"
    >
      <div class="detail-info" v-for="(item,index) in list" :key="index"  @click="handleOpenList(item)">
        <img :src="item.workingPhoto[0].url" />
        <div class="info-content">
          <div class="title">{{ item.workingTitle }}</div>
          <div class="content">{{ item.workingContent }}</div>
          <div class="time">
            <van-icon name="label-o" /> {{ item.workingMethod }}
          </div>
        </div>
      </div>
    </van-list>
  </div> 
</template>

<script>
import { workTypeList, handBookList } from '@/api/publicline/team.js'
import { Toast } from 'vant'

export default {
  components: {  },
  props: {
    active: String
  },
  data() {
    return {
      title: '',
      workType: '',
      typeList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 15
      },
      loading: false,
      finished: false,
      list: [],
    }
  },
  mounted() {
    this.getTypes()
    this.loadData(true)
  },
  beforeDestroy() {
    Toast.clear()
  },
  methods: {
    // 分类
    async getTypes() {
      const res = await workTypeList({ id: this.active })
      const { result, success } = res
      if(success) {
        this.typeList = []
        this.typeList.push({ text: '全部', value: '' })
        result.map(item => {
          this.typeList.push({ text: item.simple_working_method, value: item.working_id })
        })
      }
    },
    handleSearch(val) {
      this.title = val
      this.loadData(true)
    },
    handleDrop(val) {
      this.workType = val
      this.loadData(true)
    },
    async loadData(force) {
      // 改变搜索条件，重新查询
      if ( force ) {
        this.queryParams.pageNum = 1
        this.list = []
        this.finished = false
      }
      this.loading = true
      const params = {
        title: this.title,
        workType: this.workType,
        handbookType: this.active,
        gridId: this.$gridId,
        ...this.queryParams
      }
      const res = await handBookList(params)
      const { result, success } = res
      if(success) {
        if(result.records.length < this.queryParams.pageSize) {
          Toast({
            message: '已全部加载',
            duration: 500,
            position: 'bottom',
            forbidClick: 'true'
          });
          this.finished = true
        }
        if(result.records.length != 0) {
          result.records.map(item => {
            item.workingPhoto = JSON.parse(item.workingPhoto)
          })
        }
        this.list = this.list.concat(result.records)
        this.loading = false
        Toast.clear()
      }
    },
    onload() {
      this.loading = false
      if(this.finished === false) {
        Toast({
          type:'loading',
          duration: 0,
          message: '正在加载',
          position: 'bottom',
          forbidClick: 'true'
        })
        this.queryParams.pageNum = parseInt(this.queryParams.pageNum) + 1
        this.loadData()
      } else {
        Toast({
          message: '已全部加载',
          duration: 500,
          position: 'bottom',
          forbidClick: 'true'
        })
      }
    },
    handleOpenList(item) {
      this.$open.call(this, '/publicline/team/detail',
        { id: item.id }
      )
    }
  }

}
</script>
<style lang="less" scoped>
@import '~@/assets/less/person.less';
.wise-salary-list {
  .team-search {
    margin: 6px 8px;
  }
  /deep/ .van-dropdown-menu {
    border-bottom: 1px solid #F5F5F5;
     .van-dropdown-menu__bar {
       box-shadow: unset;
     }
  }
}
.detail-info {
  box-shadow: unset;
  border-radius: 0;
  margin: 0;
  padding: 6px;
  border-bottom: 1px solid #F5F5F5;
  &:hover {
    .title {
      color: #4D98FF;
    }
  }
  img {
    width: 80px;
    height: 80px;
  }
  .info-content {
    margin-left: 6px;
  }
  .title {
    font-size: 18px;
    font-weight: 500;
  }
  .content {
    margin-top: 6px;
    font-size: 13px;
    color: #888;
    display: -webkit-box;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .tag {
    padding-left: 8px;
  }
  .time {
    color: #999;
    font-size: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 6px;
  }
}
</style>
